Skip to content

Resolve graph style data once per type instead of once per element - #2119

Closed
kmcginnes wants to merge 2 commits into
schema-view-style-perffrom
resolve-style-data-per-type
Closed

Resolve graph style data once per type instead of once per element#2119
kmcginnes wants to merge 2 commits into
schema-view-style-perffrom
resolve-style-data-per-type

Conversation

@kmcginnes

Copy link
Copy Markdown
Collaborator

Description

Style data varies only by type, but was computed once per element. Within a render pass N nodes of a type now cost one vertexStyleData call rather than N.

The memoizing closure lives in a plain create*Resolver factory rather than inside the hook because the React Compiler lint rules reject a hook that returns a closure mutating its own captured cache. That constraint is non-obvious — a two-line hook forwarding to a factory reads like a pointless wrapper — so it is recorded in docs/agents/react.md in a later PR in this stack.

The vertex resolver takes the styles whose icons are in scope, because the canvas needs only the types it draws while the schema view needs every type. That parameter is what the next PR uses to cut the canvas down from every schema type.

Also here:

  • VertexStyleLookup / EdgeStyleLookup name the shape of the two style atoms, so the contract is explicit rather than inferred at each call site.
  • useAllEdgeStyles is deleted — it has no callers now that useGraphStyles no longer consumes edge styles.
  • The style-context regression test asserts the exact selector set instead of toBeLessThanOrEqual(6), which would have passed with three extra selectors.

How to read

  1. styleDataResolvers.ts — new; the resolvers and the factories.
  2. renderedEntities.ts / useSchemaGraphData.ts — call sites.
  3. graphStyles.ts — the lookup types and the dead-code deletion.

Stack

Note

A later PR in this stack (fuse-canvas-vertex-passes) replaces this resolver layer with an eager per-type map, after review found the lazy memoization bought nothing when every caller knows its key set up front. This PR is kept as its own step because the per-type win it introduces is independent of that restructuring and the intermediate state is green. If you would rather not land the resolver layer at all, merge this and the fusing PR together.

`LabelPreview` inlined its own `new Color(...).isDark()` with no guard for the
empty `labelColor` an imported style file can carry, so the preview could throw
where the canvas does not. Both now call `labelTextColorFor`, memoized because
parsing a color is the only non-trivial work here.

Also reads the fallback from `appDefaultEdgeStyle.labelColor` rather than
repeating the hex, and looks up line dash patterns through a `Map` so a
`lineStyle` colliding with `Object.prototype` cannot resolve to a function.
Style data varies only by type, so within a render pass N elements of a type now
cost one `vertexStyleData` call rather than N. The memoizing closure lives in a
plain `create*Resolver` factory because the React Compiler lint rules reject a
hook that returns a closure mutating its own captured cache.

The vertex resolver takes the styles whose icons are in scope, since the canvas
needs only the types it draws while the schema view needs every type. Names the
atom lookups (`VertexStyleLookup`, `EdgeStyleLookup`) so that contract is
explicit, drops the now-callerless `useAllEdgeStyles`, and tightens the
style-context test to assert the exact selector set.
Base automatically changed from share-label-text-color-helper to schema-view-style-perf August 14, 2026 20:52
@kmcginnes
kmcginnes marked this pull request as ready for review August 14, 2026 20:54
@kmcginnes

Copy link
Copy Markdown
Collaborator Author

Superseded by #2128, which consolidates this stack into a single PR targeting #2112. Same commits, same end state — the branch there is byte-identical to the tree these were cut from, rebased onto schema-view-style-perf after #2118 was squash-merged into it.

@kmcginnes kmcginnes closed this Aug 14, 2026
@kmcginnes
kmcginnes deleted the resolve-style-data-per-type branch August 14, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant